﻿// (c)2010 David Schwarz (david.schwarz@live.com)
// This file is licensed under GNU GPL v2 license, see more at http://www.gnu.org/licenses/gpl-2.0.html
namespace Z2.Editor
{

	#region Using

	using System;
	using System.Collections.Generic;
	using System.Text;

	#endregion

	/// <summary>
	/// Políčko mapy
	/// </summary>
	public class EditorField
	{

		#region Members

		private static List<long> _ids;

		private long m_id;
		private EditorObject m_obj;

		#endregion

		#region Constructor

		/// <summary>
		/// Statický konstruktor
		/// </summary>
		static EditorField()
		{
			_ids = new List<long>();
		}

		/// <summary>
		/// Konstruktor pro existující pole mapy
		/// </summary>
		/// <param name="id">Identifikátor</param>
		/// <param name="obj"><see cref="EditorObject"/></param>
		public EditorField(long id, EditorObject obj)
		{
			this.m_id = id;
			this.m_obj = obj;
			_ids.Add(id);
		}

		/// <summary>
		/// Editor pro nové pole mapy
		/// </summary>
		/// <param name="obj"><see cref="EditorObject"/></param>
		public EditorField(EditorObject obj)
		{
			// Vygenerování unikátního ID
			Random rnd = new Random();
			int id = rnd.Next(int.MinValue, int.MaxValue);
			while (_ids.Contains(id))
			{
				id = rnd.Next(int.MinValue, int.MaxValue);
			}
			_ids.Add(id);

			this.m_id = id;
			this.m_obj = obj;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Metoda smaže všechny pole
		/// </summary>
		public static void Clear()
		{
			_ids.Clear();
		}

		/// <summary>
		/// Smaže toto pole
		/// </summary>
		public void Remove()
		{
			_ids.Remove(this.m_id);
			this.m_obj = null;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Vrací unikátní ID
		/// </summary>
		public long ID
		{
			get
			{
				return this.m_id;
			}
		}

		/// <summary>
		/// Vrací <see cref="EditorObject"/>
		/// </summary>
		public EditorObject EditorObject
		{
			get
			{
				return this.m_obj;
			}
		}

		#endregion

	}
}
